home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / pcpilot.arc / SCR.ARC / GETFNAME.C < prev    next >
Text File  |  1990-01-14  |  2KB  |  90 lines

  1. /*
  2.     GETFNAME.C - Get a filename\path string from the user.
  3.  
  4.     Modified from ScrGetS() in SCR.C
  5. */
  6.  
  7. #include "scr.h"
  8. #include "kbd.h"
  9. #include <dos.h>
  10.  
  11. GetFname(char *Buffer, int Attr, int Col, int Row, int Length)
  12. /*
  13.     The function returns one of the following codes indicating the field
  14.     exit key pressed by the user:
  15.  
  16.         -1    <Esc>
  17.          0    <CR>
  18.          1    <Left-Arrow>
  19.          2    <Right-Arrow>
  20. */
  21. {
  22.     register int CurCol, i;            /* current column/loop index            */
  23.     int VideoSeg;                    /* segment of video memory              */
  24.     int far *Video;                    /* far pointer to video memory          */
  25.     int Key;                        /* stores input key value               */
  26.     int FirstChar = 1;                /* flag to indicate the first character */
  27.  
  28.     CurCol = Col;                        /* Initialize current column        */
  29.     if (*(char far *)0x00400049 == 7)
  30.         VideoSeg = 0xb000;
  31.     else
  32.         VideoSeg = 0xb800;
  33.  
  34.     Video = MK_FP (VideoSeg, Row*160+Col*2);
  35.     ScrPutAttr(Attr, CurCol, Row, CurCol, Row);
  36.  
  37.     if (*Buffer != '\0')    {
  38.         CurCol += strlen(Buffer);
  39.         while (*Buffer)
  40.             *Video++ = (Attr << 8) | *Buffer++;
  41.     }
  42.     ScrSetCur(CurCol,Row,0);
  43.  
  44.     for (;;)                /* Keyboard read loop */
  45.         switch (Key = KbdGetC ())
  46.             {
  47.             case 0x011b:        /* Escape                                    */
  48.                 return (-1);
  49.             case 0x4b00:        /* Left-Arrow                               */
  50.                 return (1);
  51.             case 0x4d00:        /* Right-Arrow                               */
  52.                 return (2);
  53.             case 0x1c0d:        /* Return                                   */
  54.                 *Buffer++ = '\0';
  55.                 return (0);
  56.             case 0x0e08:        /* Backspace                               */
  57.                 if (CurCol > Col)    {
  58.                     FirstChar = 0;
  59.                     ScrSetCur (--CurCol,Row, 0);
  60.                     *--Video = (Attr << 8) | ' ';
  61.                     *--Buffer = ' ';
  62.                 }
  63.                 break;
  64.             default:
  65.                 if (CurCol >= Col + Length - 1)        /* Test end of buffer   */
  66.                     break;
  67.                 if (Key&0x00ff == 0)            /* Test for non-ASCII char  */
  68.                     break;
  69.                 Key = toupper (Key&0x00ff);
  70.                 Key &= 0x00ff;                    /* Remove extended code     */
  71.                                     /* Place key in video memory & buffer   */
  72.                 *Video++ = (Attr << 8) | Key;
  73.                 *Buffer++ = Key;
  74.                 ScrSetCur (++CurCol, Row,0);    /* Update cursor position   */
  75.  
  76.                 if (FirstChar)        /* Blank-fill buffer on first character */
  77.                 {
  78.                     FirstChar = 0;
  79.                     while(CurCol > Col)    {
  80.                         *Buffer = '\0';
  81.                         ScrSetCur(--CurCol, Row, 0);
  82.                         *--Video = (Attr << 8) | ' ';
  83.                         *--Buffer = ' ';
  84.                     }
  85.                     *Video++ = (Attr << 8) | Key;     /* ? */
  86.                     *Buffer++ = Key;
  87.                     ScrSetCur(++CurCol, Row, 0);
  88.                 }
  89.             }
  90. }